#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# Project: spd-sxmcc
"""
@author: lyndon
@time Created on 2019/2/18 14:34
@desc
"""
from concurrent.futures import ThreadPoolExecutor

from countdown import CountDownLatch


def func(n, cdl):
    import time
    time.sleep(3)
    # print(n)
    cdl.countDown()
    return n * n


def call_back(m):
    # print(m.__dict__)
    print('结果是 %s' % (m.result()))


if __name__ == '__main__':
    cdl = CountDownLatch(2)
    tpool = ThreadPoolExecutor(max_workers=5, thread_name_prefix='sub-task-')  # 默认 不要超过cpu个数*5

    rets = []
    for i in range(20):
        t = tpool.submit(func, i, cdl).add_done_callback(call_back)

    print('设置阻塞...')
    cdl.await()



